package com.tn.service.weigh.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tn.controller.alarm.common.model.CommonVO;
import com.tn.controller.alarm.common.model.PageResult;
import com.tn.controller.alarm.common.model.weigh.vo.WeighLogInfoVO;
import com.tn.controller.alarm.common.model.weigh.vo.WeighLogQueryVO;
import com.tn.dao.mbpdao.WeightloginfoDelete;
import com.tn.dao.mbpdao.WeightloginfoDeleteMapper;
import com.tn.dao.weigh.IWeighDao;
import com.tn.service.weigh.WeightloginfoDeleteService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YuzSuzuki
 * @since 2023-06-12
 */
@Service
public class WeightloginfoDeleteServiceImpl extends ServiceImpl<WeightloginfoDeleteMapper, WeightloginfoDelete> implements WeightloginfoDeleteService {


    @Autowired
    private IWeighDao weighDao;


    @Override
    public CommonVO<PageResult<WeighLogInfoVO>> getWeighLogInfo(Integer curPage, Integer pageSize, WeighLogQueryVO queryVO) {
        CommonVO<PageResult<WeighLogInfoVO>> resultCommonVO = new CommonVO<>();
        if (!StringUtils.isEmpty(queryVO.getWeightWhere())) {
            String[] weightWhere = queryVO.getWeightWhere().split(",");
            if (weightWhere.length > 1) {
                queryVO.setWeight(Float.valueOf(weightWhere[1]));
                queryVO.setCharCompare(weightWhere[0]);
            }
        }
        int totalCount = weighDao.queryWeighLogInfoCount1(queryVO);
        PageResult<WeighLogInfoVO> result = new PageResult<>(curPage, pageSize, totalCount);
        result.setData(weighDao.queryWeighLogInfoByPage1(result.getStartIndex(), pageSize, queryVO));
        resultCommonVO.setData(result);
        return resultCommonVO;
    }
}
